package cn.wolfcode.luowowo.mgrsite.job;

import cn.wolfcode.luowowo.acticle.service.IStrategyDetailService;
import cn.wolfcode.luowowo.acticle.vo.StrategyStatisVO;
import cn.wolfcode.luowowo.cache.prefix.StrategyStatisKeyPrefix;
import cn.wolfcode.luowowo.cache.service.IStrategyStatisRedisService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * redis数据持久化
 */
@Component
public class RedisDataPersistenceJob {

    @Reference
    private IStrategyDetailService strategyDetailService;
    @Reference
    private IStrategyStatisRedisService strategyStatisRedisService;
    //秒 分 小时 月份中的日期 月份 星期中的日期 年份
    //0 0 0 1/1 * ? 
    @Scheduled(cron="0 0 0 1/1 * ?")
    public void redisDataPersistence(){
        System.out.println("---------------begin---------------------");
        String keyPattern = StrategyStatisKeyPrefix.STRATEGY_STATIS_VO.getPrefix() + ":*";
        List<StrategyStatisVO> list = strategyStatisRedisService.getStatisVOs(keyPattern);
        for (StrategyStatisVO vo : list) {
            strategyDetailService.updateStatis(vo);
        }
        System.out.println("---------------end---------------------");
    }
}